﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using YhmOA.Model;
using YhmOA.Common;

namespace YhmOA.Integrated.Letter
{
    public partial class CompanyInfo : FormPage<Integrated_Letter_Company>
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (this._ID == 0)
                {
                    this.btn_Add.Visible = true;
                    this.btn_Update.Visible = false;
                }
                else
                {
                    this.btn_Add.Visible = false;
                    this.btn_Update.Visible = true;
                }
                LoadData();
            }
        }

        protected void btn_Save_Click(object sender, EventArgs e)
        {
            Integrated_Letter_Company info = base.CreateInstance();
            if (this._ID == 0)
            {

                if (this.Dal.Add(info))
                {
                    //刷新父页面
                    ExecClientScript("try{window.parent.Search();}catch(ex){}");
                    MessageBox("成功");
                }
                else
                {
                    MessageBox("失败");
                }
            }
            else
            {
                if (this.Dal.Update(info, this._ID))
                {
                    //刷新父页面
                    ExecClientScript("try{window.parent.Search();}catch(ex){}");
                    MessageBox("成功");
                }
                else
                {
                    MessageBox("失败");
                }
            }
        }
    }
}